package cn.com.se.sharepictrue.widget;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import java.lang.ref.WeakReference;

import cn.com.se.sharepictrue.AppContext;

/**
 * Created by KIDNG on 2015/11/13.
 */
public abstract class HttpHandler extends Handler {
    WeakReference<Activity> mActivityReference;
    public static final int MSG_WHAT_SUCCESS = -1;
    public static final int MSG_WHAT_START= -2;
    public static final int MSG_WHAT_FAIL = -3;
    public static final int MSG_WHAT_NET_ERROR = -4;
    public HttpHandler(Activity activity) {
        mActivityReference= new WeakReference<Activity>(activity);
    }

    @Override
    public void handleMessage(Message msg) {
        Activity activity = mActivityReference.get();
        if(activity == null)
            Log.e("test", "activity is null");
        if (activity != null) {
            if(msg.what == MSG_WHAT_START)
                start(msg);
            else if(msg.what==MSG_WHAT_SUCCESS)
                success(msg);
            else if(msg.what == MSG_WHAT_FAIL)
                fail(msg);
            else if(msg.what == MSG_WHAT_NET_ERROR)
                internetError(msg);
        }
    }

    public abstract void success(Message msg);
    public abstract void start(Message msg);
    public abstract void fail(Message msg);
    public abstract void internetError(Message msg);
}
